#include "nosal/log/logger.h"
#include "nosal/log/log_stream.h"
#include "nosal/log/internal/log_manager.h"
#include "gtest/gtest.h"

using namespace ::testing;
using namespace netaos::nosal::log;
using LogManager = netaos::nosal::log::internal::LogManager;

namespace
{
static constexpr char ctxId[]{"CTX"};
static constexpr char ctxDescr[]{"test context"};
}  // namespace

struct LoggerTest : Test
{
    void SetUp() override
    {
	const auto logLevel = LogLevel::kVerbose;
        logManager->Initialize("TEST_LOGGER", "Other attempt with new appId", LogLevel::kFatal, LogMode::kRemote, "");

//        auto& logger = logManager->CreateLogContext(ctxId, ctxDescr, logLevel);

    }
    void TearDown() override
    {
    }
    void resetLogManager()
    {
        logManager.reset();
    }

    std::unique_ptr<LogManager> logManager{std::make_unique<LogManager>()};
};

TEST_F(LoggerTest, withLevelShouldReturnNewLogStream)
{
    const auto logLevel = LogLevel::kError;

    auto& logger = logManager->CreateLogContext(ctxId, ctxDescr, logLevel);

    auto stream = logger.WithLevel(LogLevel::kInfo);
    stream << "1234567890";

    auto stream2 = logger.WithLevel(LogLevel::kWarn);
    stream2 << 3.14;

    auto stream3 = logger.WithLevel(LogLevel::kError);
    stream3 << "100";

    auto stream4 = logger.WithLevel(LogLevel::kFatal);
    stream4 << "hello";


//    resetLogManager();
}
#if 0
struct LoggerParamTest : TestWithParam<LogLevel>
{
    void SetUp() override
    {
    }
    void TearDown() override
    {
    }

    LogManager logManager;
};

#if 0
INSTANTIATE_TEST_CASE_P(AllLogLevelsExceptOff,
    LoggerParamTest,
    Values(LogLevel::kFatal, LogLevel::kError, LogLevel::kWarn, LogLevel::kInfo, LogLevel::kDebug, LogLevel::kVerbose));

TEST_P(LoggerParamTest, shouldNotBeEnabledForLogLevelOff)
{
    auto& logger = logManager.CreateLogContext(ctxId, ctxDescr, GetParam());

    EXPECT_FALSE(logger.IsEnabled(LogLevel::kOff));
}

TEST_P(LoggerParamTest, shouldBeEnabled)
{
    auto& logger = logManager.CreateLogContext(ctxId, ctxDescr, LogLevel::kVerbose);

    EXPECT_TRUE(logger.IsEnabled(GetParam()));
}
#endif

TEST_F(LoggerParamTest, shouldCreateLogStream)
{
    auto& logger = logManager.CreateLogContext(ctxId, ctxDescr, LogLevel::kVerbose);

    {
        logger.LogFatal();
    }

    {
        logger.LogError();
    }

    {
        logger.LogWarn();
    }

    {
        logger.LogInfo();
    }

    {
        logger.LogDebug();
    }

    {
        logger.LogVerbose();
    }
}

TEST_F(LoggerParamTest, shouldCreateLogStreamWhenLogLevelMatches)
{
    auto& logger = logManager.CreateLogContext(ctxId, ctxDescr, LogLevel::kWarn);

    {
        logger.LogFatal();
    }

    {
        logger.LogError();
    }

    {
        logger.LogWarn();
    }

    logger.LogInfo();
    logger.LogDebug();
    logger.LogVerbose();
}
#endif

